﻿<UserControl x:Class="MergeTool.UI.Views.Merging"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:viewModels="clr-namespace:MergeTool.UI.ViewModels"
             xmlns:helpers="clr-namespace:MergeTool.UI.Helpers"
             mc:Ignorable="d" 
             d:DesignHeight="500" d:DesignWidth="400">

    <UserControl.Resources>
        <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
            <Setter Property="Margin" Value="10"/>
        </Style>
        <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
            <Setter Property="Margin" Value="10"/>
        </Style>
        <Style TargetType="{x:Type RadioButton}" BasedOn="{StaticResource {x:Type RadioButton}}">
            <Setter Property="Margin" Value="0,0,0,3"/>
        </Style>
        <Style TargetType="{x:Type CheckBox}" BasedOn="{StaticResource {x:Type CheckBox}}">
            <Setter Property="Margin" Value="10"/>
        </Style>
        <helpers:EnumMatchToBooleanConverter x:Key="EnumConverter" />
        <helpers:EnumBooleanConverter x:Key="EnumBooleanConverterWithNonBooleanValues" />
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    </UserControl.Resources>

    <UserControl.DataContext>
        <viewModels:MergingSettingsViewModel />
    </UserControl.DataContext>

    <Grid Style="{StaticResource ContentRoot}">
        <ScrollViewer HorizontalScrollBarVisibility="Auto">
            <StackPanel MinWidth="200">
                <TextBlock Text="Merge tool settings" Style="{StaticResource Heading2}" />
                <Grid Margin="0,20,0,0" VerticalAlignment="Center" HorizontalAlignment="Left">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="Auto"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                    </Grid.ColumnDefinitions>

                    <TextBlock Grid.Column="0" Grid.Row="0">Always show check-in dialog:</TextBlock>
                    <CheckBox Grid.Column="1" Grid.Row="0" IsChecked="{Binding Path=IsAlwaysShowCheckinConfirmation, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />


                    <TextBlock Grid.Column="0" Grid.Row="1">Merge by:</TextBlock>
                    <StackPanel Grid.Column="1" Grid.Row="1" Orientation="Vertical" Margin="10,0,0,0">
                        <RadioButton GroupName="MergeBy" Content="Branch" IsChecked="{Binding Source={StaticResource MainViewModel}, Path=IsMergeByChangesets, Mode=TwoWay, 
                                 Converter={StaticResource EnumConverter},
                                 ConverterParameter=false}" />
                        <RadioButton GroupName="MergeBy" Content="Changeset" IsChecked="{Binding Source={StaticResource MainViewModel}, Path=IsMergeByChangesets, Mode=TwoWay, 
                                 Converter={StaticResource EnumConverter},
                                 ConverterParameter=true}" />
                    </StackPanel>

                    <TextBlock Grid.Column="0" Grid.Row="2">Default branch comment pattern:</TextBlock>
                    <TextBox Grid.Column="1" Grid.Row="2" TextAlignment="Left" MinWidth="150" Text="{Binding ValidatesOnNotifyDataErrors=True, 
                        Path=DefaultBranchCheckinCommentPattern, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

                    <TextBlock Grid.Column="0" Grid.Row="3">Default changeset comment pattern:</TextBlock>
                    <TextBox Grid.Column="1" Grid.Row="3" TextAlignment="Left" MinWidth="150" Text="{Binding ValidatesOnNotifyDataErrors=True, 
                        Path=DefaultChangesetCheckinCommentPattern, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

                    <TextBlock Grid.Column="0" Grid.Row="4">Keep merge history in comments:</TextBlock>
                    <CheckBox Grid.Column="1" Grid.Row="4" IsChecked="{Binding Path=IsKeepMergeHistoryInComments, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

                    <TextBlock Grid.Column="0" Grid.Row="5">Branch name only in comments:</TextBlock>
                    <CheckBox Grid.Column="1" Grid.Row="5" IsChecked="{Binding Path=BranchNameOnlyInComments, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

                    <TextBlock Grid.Column="0" Grid.Row="6" VerticalAlignment="Center" HorizontalAlignment="Left">Work item id to associate:</TextBlock>
                    <TextBox Grid.Column="1" Grid.Row="6" 
                             Text="{Binding ValidatesOnNotifyDataErrors=True, 
                        Path=DefaultWorkItemToAssociate,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" HorizontalAlignment="Left" TextAlignment="Left" Width="80">
                        <Validation.ErrorTemplate>
                            <ControlTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <!-- Placeholder for the TextBox itself -->
                                    <AdornedElementPlaceholder x:Name="textBox"/>
                                    <TextBlock Margin="10,0,0,0" Text="{Binding [0].ErrorContent}" Foreground="Red" FontWeight="Medium" VerticalAlignment="Center" HorizontalAlignment="Center" />
                                </StackPanel>
                            </ControlTemplate>
                        </Validation.ErrorTemplate>
                    </TextBox>

                    <TextBlock Grid.Column="0" Grid.Row="7" VerticalAlignment="Center">Associate default work item:</TextBlock>
                    <StackPanel Grid.Column="1" Grid.Row="7" Orientation="Vertical" Margin="10,0,0,0">
                        <RadioButton GroupName="AssociateWhen" Content="Always" IsChecked="{Binding Path=DefaultWorkItemAssociation, Mode=TwoWay, 
                                 Converter={StaticResource EnumBooleanConverterWithNonBooleanValues},
                                 ConverterParameter=Always}" />
                        <RadioButton GroupName="AssociateWhen" Content="Never" IsChecked="{Binding Path=DefaultWorkItemAssociation, Mode=TwoWay, 
                                 Converter={StaticResource EnumBooleanConverterWithNonBooleanValues},
                                 ConverterParameter=Never}" />
                        <RadioButton GroupName="AssociateWhen" Content="If no other work item associated" IsChecked="{Binding Path=DefaultWorkItemAssociation, Mode=TwoWay, 
                                 Converter={StaticResource EnumBooleanConverterWithNonBooleanValues},
                                 ConverterParameter=OnlyWhenNoWorkItemAssociated}" />
                    </StackPanel>

                    <TextBlock Grid.Column="0" Grid.Row="8">MergeTool temp workspace path:</TextBlock>
                    <TextBox Grid.Column="1" Grid.Row="8" TextAlignment="Left" MinWidth="150" Text="{Binding ValidatesOnNotifyDataErrors=True, 
                        Path=TempWorkspacePath,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

                    <TextBlock Grid.Column="0" Grid.Row="9">Merge only mine changesets:</TextBlock>
                    <CheckBox Grid.Column="1" Grid.Row="9" IsChecked="{Binding Source={StaticResource MainViewModel}, Path=MergeLoggedUserChangesets, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

                    <TextBlock Grid.Column="0" Grid.Row="10">Keep original owner of changeset:</TextBlock>
                    <CheckBox Grid.Column="1" Grid.Row="10" IsChecked="{Binding Source={StaticResource MainViewModel}, Path=IsKeepOriginalOwnerOfMergedChangeset, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

                    <TextBlock Grid.Column="0" Grid.Row="11" Visibility="{Binding Path=IsUsingCabFeatures, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}" >Automatic version increase:</TextBlock>
                    <CheckBox Grid.Column="1" Grid.Row="11" IsChecked="{Binding Path=IsAutomaticVersionIncrease, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Visibility="{Binding Path=IsUsingCabFeatures, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}" />
                    <TextBlock Grid.Column="0" Grid.Row="12" Visibility="{Binding Path=IsUsingCabFeatures, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">Special versioning branch:</TextBlock>
                    <TextBox Grid.Column="1" Grid.Row="12" TextAlignment="Left" Width="150" HorizontalAlignment="Left" IsEnabled="{Binding Path=IsAutomaticVersionIncrease, Mode=OneWay}" Text="{Binding  
                        Path=SpecialVersioningBranch,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Visibility="{Binding Path=IsUsingCabFeatures, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}" />

                    <TextBlock Grid.Column="0" Grid.Row="13" Visibility="{Binding Path=IsUsingCabFeatures, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">Path to BeyondCompare tool:</TextBlock>
                    <TextBox Grid.Column="1" Grid.Row="13" TextAlignment="Left" MinWidth="150" HorizontalAlignment="Left" IsEnabled="{Binding Path=IsAutomaticVersionIncrease, Mode=OneWay}" Text="{Binding  
                        Path=BeyondComparePath,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Visibility="{Binding Path=IsUsingCabFeatures, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}" />
                </Grid>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</UserControl>
